<template>
  <div class="budgetContainer">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>预算管理</span>
      </div>
      <el-table
        :cell-style="{textAlign:'center'}"
        :data="budgetData"
        :header-cell-style="{textAlign:'center'}"
        style="width: 100%"
      >
        <el-table-column
          label="修建地址"
          prop="buildAddress"
        />
        <el-table-column
          label="修建日期"
          prop="buildDate"
        />
        <el-table-column
          label="修建类型"
          prop="buildType"
        >
          <template slot-scope="scope">
            <span>{{scope.row===1 ?'自建':'农业补贴'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="冷库类型"
          prop="catgory"
        />
        <el-table-column
          label="height"
          prop="高（单位米）"
        />
        <el-table-column
          label="长（单位米）"
          prop="length"
        />
        <el-table-column
          label="用户id"
          prop="userId"
        />
        <el-table-column
          label="用户手机号"
          prop="mobile"
        />
        <el-table-column
          label="宽（单位米）"
          prop="width"
        />
        <el-table-column
          label="冷库体积"
          prop="volume"
        />
        <el-table-column
          label="操作"
          :render-header="renderHeader"
        >
          <template slot-scope="scope">
            <el-button type="danger" size="mini" @click="del(scope.row)">删除</el-button>
            <el-button type="danger" size="mini" @click="edit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        style="margin: 20px 0;float: right"
        v-show="queryParams.total>0"
        :total="queryParams.total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getData"
      />
    </el-card>
  </div>
</template>

<script>
import {delBudgetList, getBudgetList} from "@/api/budget";

export default {
  name: 'Budget',
  data(){
    return{
      //分页查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        total:0
      },
      id:"",
      budgetData:[
      ]
    }
  },
  created() {
    this.getData()
  },
  methods: {
    //获取预算管理数据
    getData() {
      getBudgetList().then(res => {
        this.budgetData = res.data.records
        this.queryParams.total = res.data.total
      })
    },
  //  删除预算管理信息
    del(row){
      const id=row.id
      this.$confirm('您确定删除这条数据么？','提示',{
        confirmButtonText:"确定",
        cancelButtonText:"取消",
        type:"warning"
      }).then(()=>{
        delBudgetList(id).then(()=>{
          this.$message.success('删除成功')
          this.getData()
        })
      }).catch(()=>{
        this.$message.info('您已取消操作')
      })
    },
    renderHeader(h) {
      return (
        <div>操作
          <el-button type="success" size="mini" onClick={() => this.handleAddItem()} style="margin-left:20px"
          >添加</el-button>
        </div>
      )
    },
  //  跳转到新增页面
    handleAddItem(){
      this.$router.push('/addBudget')
    }
  }
}
</script>

<style scoped lang="scss">
.budgetContainer{
  padding: 20px;
}
</style>
